package com.sinog.auth.util;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import java.nio.charset.StandardCharsets;
import java.util.Map;

/**
 * @desc 解析token工具类
 * @author Administrator
 * @date -
 */
public class TokenParseUtils {

    /**
     * jwt解析
     * @param token token秘 ⽂字符串
     * @return String
     */
    public static Map<String,Object> jwtParseToken(String token,String singeKey){
        Claims claims = Jwts.parser().setSigningKey(singeKey.getBytes(StandardCharsets.UTF_8)).parseClaimsJws(token).getBody();
        return (Map<String,Object>)claims.get("expand");
    }

    /**
     * AES解密
     * @param token token秘⽂字符串
     * @return String
     */
    public static String decryptStr(String token,String singeKey) {
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, Base64.decode(singeKey));
        return aes.decryptStr(token, CharsetUtil.CHARSET_UTF_8);
    }
}